package com.gl.rent;


import com.haixiaoke.saas.repository.core.AjaxResult;
import com.haixiaoke.saas.repository.core.BaseController;
import com.haixiaoke.saas.repository.core.page.TableDataInfo;
import com.haixiaoke.saas.repository.pojo.Banner;
import com.haixiaoke.saas.repository.service.IBannerService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.web.bind.annotation.*;

import java.util.List;


/**
 * 轮播Controller
 *
 * @author zhiping
 * @date 2023-06-02
 */
@RestController
@RequestMapping("/business/banner")
public class BannerController extends BaseController {
    @Autowired
    private IBannerService bannerService;

    /**
     * 查询轮播列表
     */
    @GetMapping("/list")
    public TableDataInfo list(Banner banner) {
        startPage();
        List<Banner> list = bannerService.selectBannerList(banner);
        return getDataTable(list);
    }


    /**
     * 获取轮播详细信息
     */
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") Long id) {
        return success(bannerService.selectBannerById(id));
    }

    /**
     * 新增轮播
     */
    @PostMapping
    @PreAuthorize("@ps.hasPermi('business:banner:add')")
    public AjaxResult add(@RequestBody Banner banner) {
        return toAjax(bannerService.insertBanner(banner));
    }

    /**
     * 修改轮播
     */
    @PutMapping
    @PreAuthorize("@ps.hasPermi('business:banner:edit')")
    public AjaxResult edit(@RequestBody Banner banner) {
        return toAjax(bannerService.updateBanner(banner));
    }

    /**
     * 删除轮播
     */
    @PreAuthorize("@ps.hasPermi('business:banner:remove')")
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable Long[] ids) {
        return toAjax(bannerService.deleteBannerByIds(ids));
    }
}
